package com.tuocent.dagv2.controller.RestApi;

import com.tuocent.dagv2.common.AjaxResult;
import com.tuocent.dagv2.common.entity.LoginUser;
import com.tuocent.dagv2.service.IProjectsService;
import com.tuocent.dagv2.service.ITaskService;
import com.tuocent.dagv2.service.IUsersService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("RestApi/system")
public class RestSystemController {
    @Autowired
    private IUsersService usersService;
    @Autowired
    private IProjectsService projectsService;
    @Autowired
    private ITaskService tasksService;

    @GetMapping("checkServer")
    @ResponseBody
    public AjaxResult checkServer() {
        return AjaxResult.success();
    }

    @PostMapping("/userLogin")
    @ResponseBody
    public AjaxResult userLogin(HttpServletRequest request, HttpSession session,
                                @RequestBody LoginUser userInfo) throws Exception {
        return usersService.RestUserLogin(request, userInfo, session);
    }

    @GetMapping("getAllProjectInfo")
    @ResponseBody
    public AjaxResult getAllProjectInfo() {
        return projectsService.getAllProjectInfo();
    }

    @GetMapping("getUserTaskInfo")
    @ResponseBody
    public AjaxResult getUserTaskInfo(HttpSession session,
                                      @RequestParam("pid") String pid) {
        return tasksService.getUserTaskInfo(session, pid, 0, 0);
    }

}
